<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>任务完成申请调试</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        .debug-section {
            border: 1px solid #ddd;
            padding: 20px;
            margin: 20px 0;
            border-radius: 8px;
        }
        .test-button {
            background: #007bff;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 4px;
            cursor: pointer;
            margin: 5px;
        }
        .test-button:hover {
            background: #0056b3;
        }
        .log-output {
            background: #f8f9fa;
            border: 1px solid #e9ecef;
            padding: 10px;
            border-radius: 4px;
            font-family: monospace;
            white-space: pre-wrap;
            max-height: 300px;
            overflow-y: auto;
        }
        .status-indicator {
            display: inline-block;
            width: 12px;
            height: 12px;
            border-radius: 50%;
            margin-right: 8px;
        }
        .status-pending { background: #ffc107; }
        .status-approved { background: #28a745; }
        .status-rejected { background: #dc3545; }
        .status-withdrawn { background: #6c757d; }
    </style>
</head>
<body>
    <h1>任务完成申请调试工具</h1>
    
    <div class="debug-section">
        <h3>1. 消息类型测试</h3>
        <p>测试消息类型常量是否正确导入：</p>
        <button class="test-button" onclick="testMessageTypes()">测试消息类型</button>
        <div id="message-types-output" class="log-output"></div>
    </div>
    
    <div class="debug-section">
        <h3>2. 模拟消息点击</h3>
        <p>模拟不同类型的任务完成申请消息：</p>
        <button class="test-button" onclick="testPendingCompletion()">测试待处理申请</button>
        <button class="test-button" onclick="testApprovedCompletion()">测试已同意申请</button>
        <button class="test-button" onclick="testRejectedCompletion()">测试已拒绝申请</button>
        <div id="click-test-output" class="log-output"></div>
    </div>
    
    <div class="debug-section">
        <h3>3. 对话框状态测试</h3>
        <p>测试对话框状态变化：</p>
        <button class="test-button" onclick="testDialogState()">测试对话框状态</button>
        <div id="dialog-state-output" class="log-output"></div>
    </div>
    
    <div class="debug-section">
        <h3>4. 用户信息测试</h3>
        <p>测试用户信息获取：</p>
        <button class="test-button" onclick="testUserInfo()">测试用户信息</button>
        <div id="user-info-output" class="log-output"></div>
    </div>

    <script>
        // 模拟消息类型常量
        const MessageType = {
            TASK_COMPLETION: 4,
            TASK_COMPLETION_WITHDRAWAL: -20
        };
        
        const MessageStatus = {
            UNREAD: 0,
            READ: 1,
            APPROVED: 2,
            REJECTED: 3,
            WITHDRAWN: 4
        };
        
        // 模拟用户信息
        const mockUserInfo = {
            uid: 12345,
            nickname: '测试用户',
            avatarUrl: 'https://skillith.cn/uploads/user/default-avatar.png'
        };
        
        // 模拟消息对象
        const mockMessages = {
            pending: {
                id: 1,
                type: MessageType.TASK_COMPLETION,
                status: MessageStatus.UNREAD,
                title: '任务完成申请',
                content: '用户申请完成任务',
                senderId: 67890,
                receiverId: 12345,
                taskId: 100
            },
            approved: {
                id: 2,
                type: MessageType.TASK_COMPLETION,
                status: MessageStatus.APPROVED,
                title: '任务完成申请',
                content: '用户申请完成任务',
                senderId: 67890,
                receiverId: 12345,
                taskId: 101
            },
            rejected: {
                id: 3,
                type: MessageType.TASK_COMPLETION,
                status: MessageStatus.REJECTED,
                title: '任务完成申请',
                content: '用户申请完成任务',
                senderId: 67890,
                receiverId: 12345,
                taskId: 102
            }
        };
        
        // 测试消息类型
        function testMessageTypes() {
            const output = document.getElementById('message-types-output');
            let log = '消息类型测试结果：\n\n';
            
            log += `MessageType.TASK_COMPLETION: ${MessageType.TASK_COMPLETION}\n`;
            log += `MessageType.TASK_COMPLETION_WITHDRAWAL: ${MessageType.TASK_COMPLETION_WITHDRAWAL}\n\n`;
            
            log += `MessageStatus.UNREAD: ${MessageStatus.UNREAD}\n`;
            log += `MessageStatus.READ: ${MessageStatus.READ}\n`;
            log += `MessageStatus.APPROVED: ${MessageStatus.APPROVED}\n`;
            log += `MessageStatus.REJECTED: ${MessageStatus.REJECTED}\n`;
            log += `MessageStatus.WITHDRAWN: ${MessageStatus.WITHDRAWN}\n\n`;
            
            log += '类型检查：\n';
            log += `typeof MessageType.TASK_COMPLETION: ${typeof MessageType.TASK_COMPLETION}\n`;
            log += `typeof MessageStatus.APPROVED: ${typeof MessageStatus.APPROVED}\n`;
            
            output.textContent = log;
        }
        
        // 测试待处理申请
        function testPendingCompletion() {
            const output = document.getElementById('click-test-output');
            let log = '测试待处理任务完成申请：\n\n';
            
            const msg = mockMessages.pending;
            log += `消息对象: ${JSON.stringify(msg, null, 2)}\n\n`;
            
            log += '条件检查：\n';
            log += `msg.type === MessageType.TASK_COMPLETION: ${msg.type === MessageType.TASK_COMPLETION}\n`;
            log += `msg.status !== MessageStatus.APPROVED: ${msg.status !== MessageStatus.APPROVED}\n`;
            log += `msg.status !== MessageStatus.REJECTED: ${msg.status !== MessageStatus.REJECTED}\n`;
            log += `综合条件: ${msg.type === MessageType.TASK_COMPLETION && msg.status !== MessageStatus.APPROVED && msg.status !== MessageStatus.REJECTED}\n\n`;
            
            if (msg.type === MessageType.TASK_COMPLETION && msg.status !== MessageStatus.APPROVED && msg.status !== MessageStatus.REJECTED) {
                log += '✅ 应该打开处理对话框\n';
                log += '当前用户ID: ' + mockUserInfo.uid + '\n';
                log += '发送者ID: ' + msg.senderId + '\n';
                log += '是否为发送者: ' + (mockUserInfo.uid == msg.senderId) + '\n';
                
                if (mockUserInfo.uid == msg.senderId) {
                    log += '→ 应该显示撤回选项\n';
                } else {
                    log += '→ 应该显示同意/拒绝选项\n';
                }
            } else {
                log += '❌ 不会打开处理对话框\n';
            }
            
            output.textContent = log;
        }
        
        // 测试已同意申请
        function testApprovedCompletion() {
            const output = document.getElementById('click-test-output');
            let log = '测试已同意任务完成申请：\n\n';
            
            const msg = mockMessages.approved;
            log += `消息对象: ${JSON.stringify(msg, null, 2)}\n\n`;
            
            log += '条件检查：\n';
            log += `msg.type === MessageType.TASK_COMPLETION: ${msg.type === MessageType.TASK_COMPLETION}\n`;
            log += `msg.status !== MessageStatus.APPROVED: ${msg.status !== MessageStatus.APPROVED}\n`;
            log += `msg.status !== MessageStatus.REJECTED: ${msg.status !== MessageStatus.REJECTED}\n`;
            log += `综合条件: ${msg.type === MessageType.TASK_COMPLETION && msg.status !== MessageStatus.APPROVED && msg.status !== MessageStatus.REJECTED}\n\n`;
            
            if (msg.type === MessageType.TASK_COMPLETION && msg.status !== MessageStatus.APPROVED && msg.status !== MessageStatus.REJECTED) {
                log += '✅ 应该打开处理对话框\n';
            } else {
                log += '❌ 不会打开处理对话框（已处理）\n';
            }
            
            output.textContent = log;
        }
        
        // 测试已拒绝申请
        function testRejectedCompletion() {
            const output = document.getElementById('click-test-output');
            let log = '测试已拒绝任务完成申请：\n\n';
            
            const msg = mockMessages.rejected;
            log += `消息对象: ${JSON.stringify(msg, null, 2)}\n\n`;
            
            log += '条件检查：\n';
            log += `msg.type === MessageType.TASK_COMPLETION: ${msg.type === MessageType.TASK_COMPLETION}\n`;
            log += `msg.status !== MessageStatus.APPROVED: ${msg.status !== MessageStatus.APPROVED}\n`;
            log += `msg.status !== MessageStatus.REJECTED: ${msg.status !== MessageStatus.REJECTED}\n`;
            log += `综合条件: ${msg.type === MessageType.TASK_COMPLETION && msg.status !== MessageStatus.APPROVED && msg.status !== MessageStatus.REJECTED}\n\n`;
            
            if (msg.type === MessageType.TASK_COMPLETION && msg.status !== MessageStatus.APPROVED && msg.status !== MessageStatus.REJECTED) {
                log += '✅ 应该打开处理对话框\n';
            } else {
                log += '❌ 不会打开处理对话框（已处理）\n';
            }
            
            output.textContent = log;
        }
        
        // 测试对话框状态
        function testDialogState() {
            const output = document.getElementById('dialog-state-output');
            let log = '对话框状态测试：\n\n';
            
            // 模拟对话框状态
            let showReasonDialog = false;
            let currentAction = {};
            let dialogTitle = '';
            let dialogPlaceholder = '';
            
            log += '初始状态：\n';
            log += `showReasonDialog: ${showReasonDialog}\n`;
            log += `currentAction: ${JSON.stringify(currentAction)}\n`;
            log += `dialogTitle: "${dialogTitle}"\n`;
            log += `dialogPlaceholder: "${dialogPlaceholder}"\n\n`;
            
            // 模拟设置对话框状态
            log += '设置对话框状态：\n';
            currentAction = { id: 1, type: 'task-completion', approve: true };
            dialogTitle = '处理任务完成申请';
            dialogPlaceholder = '若选择拒绝，可填写拒绝理由（可选）';
            showReasonDialog = true;
            
            log += `showReasonDialog: ${showReasonDialog}\n`;
            log += `currentAction: ${JSON.stringify(currentAction)}\n`;
            log += `dialogTitle: "${dialogTitle}"\n`;
            log += `dialogPlaceholder: "${dialogPlaceholder}"\n\n`;
            
            log += '✅ 对话框状态设置成功\n';
            
            output.textContent = log;
        }
        
        // 测试用户信息
        function testUserInfo() {
            const output = document.getElementById('user-info-output');
            let log = '用户信息测试：\n\n';
            
            log += `模拟用户信息: ${JSON.stringify(mockUserInfo, null, 2)}\n\n`;
            
            log += '用户信息获取测试：\n';
            log += `getUserInfo().uid: ${mockUserInfo.uid}\n`;
            log += `getUserInfo().nickname: ${mockUserInfo.nickname}\n`;
            log += `getUserInfo().avatarUrl: ${mockUserInfo.avatarUrl}\n\n`;
            
            log += '✅ 用户信息获取正常\n';
            
            output.textContent = log;
        }
        
        // 页面加载时自动运行测试
        window.onload = function() {
            testMessageTypes();
            testPendingCompletion();
            testDialogState();
            testUserInfo();
        };
    </script>
</body>
</html>






